﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace DapperHelper.SqlBuilder
{
    public class UpdateBuilder<T> : AbstractSqlBuilder<T>, ICondition<T>
    {
        public IList<string> Conditions { get; }
        
        public UpdateBuilder() : base()
        {
            Conditions = new List<string>();
            SqlBuilder.Append("update ").Append(TableName()).Append(" set ")
                .Append(string.Join(",", AllField.Select(v => $"{FieldName(v)}=@{FieldName(v)}")))
                .Append(" where ");
        }

        public void Condition(params Expression<Func<T, bool>>[] expressions)
        {
            foreach (Expression<Func<T, bool>> expr in expressions)
            {
                Conditions.Add(AddCondition(expr));
            }
        }

        public string AddCondition(Expression<Func<T, bool>> expr)
        {
            return string.Empty;
        }

        public override string Build()
        {
            SqlBuilder.Append(string.Join(" and ", Conditions));
            return base.Build();
        }
    }
}